@echo off

if "%1"=="" echo usage: %~n0 ^<project-name^>>&2 & goto :EOF

setlocal
set PROJECT=%1
set REPO=http://%PROJECT%.googlecode.com/svn

set LANG=C

for /F "usebackq delims=. tokens=1,2" %%I in (`svn --version --quiet`) do set /A SVN_VERSION_100=%%I*100+%%J

for /F "usebackq delims=: tokens=1,*" %%I in (`svn info "%REPO%"`) do if "%%I"=="Last Changed Rev" set LAST_REV=%%J
set LAST_REV=%LAST_REV:~1%

set OUTPUT=%PROJECT%-r%LAST_REV%

set SVN_FLAGS=
:: Version >= 1.6 ?
set /A SVN_VERSION_DIFF_106=%SVN_VERSION_100%-106
if %SVN_VERSION_DIFF_106% geq 0 set SVN_FLAGS=-g
echo %SVN_VERSION_DIFF_106% %SVN_FLAGS%

svn log --xml --verbose %SVN_FLAGS% "%REPO%" > "%OUTPUT%.svnlog"  || goto :Err
xsltproc -o "%OUTPUT%.svnfr" --stringparam url "%REPO%" svnlog2svnfr.xslt "%OUTPUT%.svnlog"  || goto :Err
xsltproc -o "%OUTPUT%.dot" svnfr2dot.xslt "%OUTPUT%.svnfr"  || goto :Err
dot -Tpng -o "%OUTPUT%.png" "%OUTPUT%.dot"
dot -Tsvg -o "%OUTPUT%.svg" "%OUTPUT%.dot"
goto :EOF

:Err
exit /B %errorlevel%
